package com.jixiang.dictionary.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jixiang.dictionary.dao.DsMenuDao;
import com.jixiang.model.common.dtos.ResponseResult;
import com.jixiang.model.dictionary.entity.DsMenu;
import com.jixiang.dictionary.service.DsMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单表(UsMenu)表服务实现类
 *
 * @author makejava
 * @since 2023-10-12 18:51:50
 */
@Service("usMenuService")
public class DsMenuServiceImpl extends ServiceImpl<DsMenuDao, DsMenu> implements DsMenuService {

    @Resource
    private DsMenuService usMenuService;

    @Override
    public ResponseResult getMenuListByAdmin() {
        List<DsMenu> list = usMenuService.query().eq("level",1).orderByAsc("priority").list();
        list.forEach( item -> {
            List<DsMenu> childrenList = usMenuService.query().eq("parent_menu_id", item.getId()).orderByAsc("priority").list();
            if(!childrenList.isEmpty()){
                item.setChildren(childrenList);
            }
        });
        return ResponseResult.okResult(list);
    }
}

